package sys.spvisor.core.service.people;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import sys.spvisor.core.dao.people.PeopleDao;
import sys.spvisor.core.dao.project.TProjectMapper;
import sys.spvisor.core.dao.project.TProjectPeopleMapper;
import sys.spvisor.core.entity.people.PeopleShowInfo;
import sys.spvisor.core.entity.people.TEvectionStatus;
import sys.spvisor.core.entity.people.TEvectionStatusExample;
import sys.spvisor.core.entity.people.TPeople;
import sys.spvisor.core.entity.people.TPeopleAndUerRole;
import sys.spvisor.core.entity.people.TPeopleExample;
import sys.spvisor.core.entity.people.TPeoplePoststatus;
import sys.spvisor.core.entity.project.TProjectPeople;
import sys.spvisor.core.entity.project.TProjectPeopleExample;
import sys.spvisor.core.entity.project.TProjectPeopleExample.Criteria;
import sys.spvisor.core.dao.people.TEvectionStatusMapper;
import sys.spvisor.core.dao.people.TPeopleMapper;

@Service
public class PeopleService {
	
	@Autowired
	private PeopleDao statusDao;
	@Autowired
	private TProjectMapper msgMapper;
	
	@Autowired
	private TEvectionStatusMapper TEvectionStatusMapper;
	@Autowired
	private TPeopleMapper tPeopleMapper;
	@Autowired
	private TProjectPeopleMapper TProjectPeopleMapper;
	//人员在岗状态
	public List<TPeoplePoststatus> getPostStatus(){

		System.out.println(statusDao.getTransferStatus());
		return statusDao.getTransferStatus();
	}
	
	@Transactional
	public List<TEvectionStatus> getHolidayTravelStatus(){
		TEvectionStatusExample example = new TEvectionStatusExample();
		
		List<TEvectionStatus> list = TEvectionStatusMapper.selectByExample(example);
 		
		return list;
	}


	public List<PeopleShowInfo> getAllPeople() {
		// TODO Auto-generated method stub
		/*TPeopleExample example = new TPeopleExample();
		List<TPeople> lists  =tPeopleMapper.selectByExample(example);*/
		List<PeopleShowInfo> lists = statusDao.getAllPeople();
		return  statusDao.getAllPeople();

	}

	public List<TPeopleAndUerRole> getAllPeopleUser() {
		// TODO Auto-generated method stub
		/*TPeopleExample example = new TPeopleExample();
		List<TPeople> lists  =tPeopleMapper.selectByExample(example);*/
		List<TPeopleAndUerRole> lists = statusDao.getAllPeopleUser();
		return  statusDao.getAllPeopleUser();

	}
	@Transactional
	public List<TPeople> selectByExample(TPeople msg) {
		// TODO Auto-generated method stub
		
		TPeopleExample example = new TPeopleExample();
		sys.spvisor.core.entity.people.TPeopleExample.Criteria criteria = example.createCriteria();	
		if(msg.getPeoName() == ""){}
		else{
			criteria.andPeoNameLike("%" +msg.getPeoName() +"%");//姓名
			}
		if(msg.getPeoEvectionLocation()==""){}
		else{
			criteria.andPeoEvectionLocationLike("%" +msg.getPeoEvectionLocation() +"%");//出差位置*/
		}		
		if(msg.getPeoStationDesc() == "") {}
		else {
			criteria.andPeoStationDescEqualTo(msg.getPeoStationDesc());//岗位状态
		}
		if(msg.getPeoEvectionDesc() == "") {}
		else {
			criteria.andPeoEvectionLocationEqualTo(msg.getPeoEvectionDesc());//休假出差
		}
		if(msg.getPeoContel()==""){}
		else{
			criteria.andPeoContelLike("%" +msg.getPeoContel() +"%");//电话
		}
		//剩下的这么多，在新修改的质量是人员表里面已经没有了
		/*if(msg.getQualityFactory()==""){}
		else{
			criteria.andQualityFactoryLike("%" +msg.getQualityFactory() +"%");//所在厂家
		}
		if(msg.getQualityProjectDuty()==""){}
		else{
			criteria.andQualityProjectDutyLike("%" +msg.getQualityProjectDuty() +"%");//项目职务
		}
		if(msg.getQualityProjectType()==""){}
		else{
			criteria.andQualityProjectTypeLike("%" +msg.getQualityProjectType() +"%");//项目类型
		}
		if(msg.getQualityName()==""){}
		else{
			criteria.andQualityProjectNameLike("%" +msg.getQualityProjectName() +"%");//项目名字
		}*/
				
		List<TPeople> lists  =tPeopleMapper.selectByExample(example);
		return lists;
	}
	
	@Transactional
	public void addPeopleData(TPeople people) throws IOException{
		// TODO Auto-generated method stub
		/*System.out.println(people.getQualityContel());
		System.out.println(people.getQualityName());
		System.out.println(people.getQualityStationDesc());*/
		tPeopleMapper.insert(people);
	}

	public void RemovePeopleData(String peoId) throws IOException{
		// TODO Auto-generated method stub
		TPeople record = new TPeople();		
		int qualityPeopleId = Integer.parseInt(peoId);
		record.setPeoId(qualityPeopleId);
		record.setPeoStationDesc("离职");
		tPeopleMapper.updateByPrimaryKeySelective(record);
		
		TProjectPeople recordStatus = new TProjectPeople();
		recordStatus.setPpStatus("C");
		TProjectPeopleExample example = new TProjectPeopleExample();
		Criteria criteria = example.createCriteria();
		criteria.andPpPeopleidEqualTo(qualityPeopleId);
		TProjectPeopleMapper.updateByExampleSelective(recordStatus, example);
	}

	public void EditPeopleData(TPeople people) throws IOException{
		// TODO Auto-generated method stub
		/*int qualityPeopleId = people.getQualityId();*/
		tPeopleMapper.updateByPrimaryKey(people);
	}
	public TPeople getPeopleById(int peoId) {
		return tPeopleMapper.selectByPrimaryKey(peoId);
	}
}
